package com.ccut.bits.security.service.impl;

import com.ccut.bits.model.Expert;
import com.ccut.bits.security.dao.ExpertDao;
import com.ccut.bits.security.service.ExpertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("expertService")
public class ExpertServiceImpl implements ExpertService {

    @Autowired
    private ExpertDao expertDao;

    @Override
    public List<Expert> getExpertListPage(Expert expert) {
        List<Expert> list = expertDao.getExpertListPage(expert);
        for(Expert data : list){
            data.setExpert0rg(expertDao.getExpertOrgByExpertId(data.getId()));
            data.setExpertTheme(expertDao.getThemeListByExpertId(data.getId()));
        }
        return list;
    }

    @Override
    public void addExpert(Expert expert) {
        expertDao.addExpertInfo(expert);
        int id = expert.getId();
        int themeId;
        for(String themeName : expert.getExpertTheme()){
            themeId = expertDao.getThemeId(themeName);
            expertDao.addExpertTheme(id, themeId);
        }
    }

    @Override
    public Expert getExpertById(int id) {
        return expertDao.getExpertById(id);
    }
}
